<?php

/**
 * 文章分类管理
 * Enter description here ...
 * @author Admin
 */
class Article_categoriesAction extends CommonAction{
	
	
	/**
	 * 文章分类列表
	 * Enter description here ...
	 */
	public function index() {
		$Article_categories = D('Article_categories');
		
		$this->page($Article_categories,$article_categoriesdata,$page);
		$this->assign("page",$page);
		
		foreach ($article_categoriesdata as &$value){
			unset($tmp);
			if (!empty($value['fid'])){
				$tmp = $Article_categories->find($value['fid']);
			}
			$value['fname'] = $tmp['name'];
		}
		
		$this->assign("article_categoriesdata",$article_categoriesdata);
		$this->display();
	}
	
	
	/**
	 * 文章分类新建
	 * @see CommonAction::add()
	 */
	public function add(){
		$Article_categories = D('Article_categories');
		$article_categoriesdata = $Article_categories->findAll();  //获取所有文章分类
		
		$this->assign("article_categoriesdata",$article_categoriesdata);
		parent::add();
	}
	
	
	/**
	 * 文章分类新建保存
	 * @see CommonAction::insert()
	 */
	public function insert(){
		$data = Init_GP(array('name','fid'));
		
		parent::insert($data);
	}
	
	
	/**
	 * 文章分类修改
	 * @see CommonAction::edit()
	 */
	public function edit(){
		$id = GetNum($_GET['id']);  //主键
		
		$Article_categories = D('Article_categories'); 
		$children = $Article_categories->getChildren($id);  //获取当前分类下属所有子分类  
		
		if (empty($children)){
			$childrenstr = $id;
		}else {
			$childrenstr = implode(',', $children).','.$id;    //implode() 函数把数组元素组合为一个字符串
		}
		
		$map['id'] = array('not in',$childrenstr);
		$article_categoriesdata = $Article_categories->where($map)->findAll();  //获取除去当前文章分类以及所有子类外的分类
		
		$this->assign("article_categoriesdata",$article_categoriesdata);
		
		parent::edit();
	}
	
	
	/**
	 * 文章分类修改确认
	 * @see CommonAction::update()
	 */
	public function update(){
		$where['id'] = GetNum($_POST['id']);  //主键
		$data = Init_GP(array('name','fid'));
		
		parent::update($data,$where);
	}
	
	
}
?>